﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UIT_CV_Management
{
    public class LyLichKhoaHoc
    {
        public String maLyLichKhoaHoc;
        String maLyLichSoLuoc;
        String maHoaDongKHKT;
        String maQuaTrinhDaoTao;
        Database myDatabase = Database.shareDatabase;
        public LyLichSoLuoc lyLichSoLuoc
        {
            get
            {
                return new LyLichSoLuoc(maLyLichSoLuoc);
            }
            set
            {
                lyLichSoLuoc = value;
            }
        }
        public HoatDongKHKT hoatDongKHKT
        {
            get
            {
                return new HoatDongKHKT(maHoaDongKHKT);
            }
            set
            {
                hoatDongKHKT = value;
            }
        }
        public QuyTrinhDaoTao quaTrinhDaoTao
        {
            get
            {
                return new QuyTrinhDaoTao(maQuaTrinhDaoTao);
            }
            set
            {
                quaTrinhDaoTao = value;
            }
        }
        public LyLichKhoaHoc(String _maLyLichKhoaHoc, String _maLyLichSoLuoc, String _maQuaTrinhDaoTao, String _maHoatDongKHKT)
        {
            maLyLichKhoaHoc = _maLyLichKhoaHoc;
            maLyLichSoLuoc = _maLyLichSoLuoc;
            maQuaTrinhDaoTao = _maQuaTrinhDaoTao;
            maHoaDongKHKT = _maHoatDongKHKT;
        }
        public LyLichKhoaHoc(String _maLyLichKhoaHoc)
        {
            QueryResult result = myDatabase.Query("SELECT * FROM LyLichKhoaHoc WHERE MaLyLichKhoaHoc = '" + _maLyLichKhoaHoc + "'");
            if (result.ReturnCode == 200)
            {
                maLyLichKhoaHoc = result.Table.Rows[0]["MaLyLichKhoaHoc"].ToString();
                maLyLichSoLuoc = result.Table.Rows[0]["MaLyLichSoLuoc"].ToString();
                maQuaTrinhDaoTao = result.Table.Rows[0]["MaQuaTrinhDaoTao"].ToString();
                maHoaDongKHKT = result.Table.Rows[0]["MaHoatDongKHKT"].ToString();
            }
        }
        public Boolean save()
        {
            QueryResult result = myDatabase.Query("INSERT INTO LyLichKhoaHoc VALUES(" +
                "'" + maLyLichKhoaHoc + "'," +
                "'" + maLyLichSoLuoc + "'," +
                "'" + maQuaTrinhDaoTao + "'," +
                "'" + maHoaDongKHKT + "')");
            if (result.ReturnCode == 200)
            {
                return true;
            }
            return false;

        }
        public Boolean delete()
        {
            QueryResult result = Database.shareDatabase.Query("DELETE FROM LyLichKhoaHoc" +
                "WHERE LyLichKhoaHoc = '" + maLyLichKhoaHoc + "'");
            if (result.ReturnCode == 200)
            {
                lyLichSoLuoc.delete();
                quaTrinhDaoTao.delete();
                hoatDongKHKT.Delete();
                return true;
            }
            else
                return false;
        }
    }
}
